<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>用户添加页</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="_token" content="{{ csrf_token() }}"/>
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        @include('admin.public.styles')
        @include('admin.public.script')
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            账号
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="username" name="username" required="" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_password" class="layui-form-label">
                            密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="password" id="password" name="password" required="" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_tel" class="layui-form-label">
                            电话
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="phone" name="phone" required="" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_email" class="layui-form-label">
                            邮件
                        </label>
                        <div class="layui-input-inline">
                            <input type="email" id="email" name="email" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_state" class="layui-form-label">
                            状态
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="state" name="state" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="add" style="margin-left:100px;width:20%;">添加</button>
                    </div>
                </form>
            </div>
        </div>
    </body>
    <script>layui.use(['form', 'layer','jquery'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                //监听提交
                form.on('submit(add)',function(data) {
                        $.ajax({
                            type:'post',
                            dataType:'json',
                            headers:{'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                            url:'/blog/public/admin/user',
                            data:data.field,
                            success:function (data) {
                                // console.log(data)
                                if(data.status==0){
                                    //发异步，把数据提交给php
                                    layer.alert(data.message, {
                                            icon: 6
                                        },
                                        function() {
                                            parent.location.reload(true);
                                            //关闭当前frame
                                            xadmin.close();
                                            // 可以对父窗口进行刷新
                                            xadmin.father_reload();
                                        });
                                    return false;
                                }
                            },error:function (data) {
                                layer.alert(data.message, {
                                    icon: 5
                                });
                            }
                        })
                    });

            });
    </script>
</html>